'use strict';
const db = uniCloud.database()
const coll = db.collection('user')
exports.main = async (event, context) => {
	//event为客户端上传的参数
	console.log('event : ', event)
	let res1 = await coll.where({
		openid: event.openid
	}).get()
	console.log(res1)
	if (res1.data.length > 0) {
		return res1
	} else {
		let res = await coll.add({
			nickname: event.nickname,
			city: event.city,
			country: event.country,
			openid: event.openid,
			headimgurl: event.headimgurl,
			sex: event.sex,
			province: event.province,
			dianzanjihui: 3,
			dianzanlist: [],
			status: 1,
			flag: 'flag'
		})
		//返回数据给客户端

		let res2 = await coll.where({
			openid: event.openid
		}).get()
		return res2
	}


};
